package com.leetcode.p300;

import com.bean.ListNode;
import com.utils.DataUtils;

public class Test328 {

    public ListNode oddEvenList(ListNode head) {
        ListNode head1 = new ListNode();
        ListNode c1 = head1;


        ListNode head2 = new ListNode();
        ListNode c2 = head2;

        int index = 0;
        while (head != null) {
            if (index % 2 == 0) {
                c1.next = head;
                c1 = c1.next;
            } else {
                c2.next = head;
                c2 = c2.next;
            }
            head = head.next;
            index++;
        }
        c2.next = null;
        c1.next = head2.next;

        return head1.next;
    }

    public static void main(String[] args) {
        Test328 test = new Test328();
        ListNode head = DataUtils.getListNode(new int[]{1, 2, 3, 4, 5});
        DataUtils.printListNode(test.oddEvenList(head));
    }
}
